home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / opendevice.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  3KB  |  116 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: opendevice.c,v 1.4 1996/08/13 13:56:05 digulla Exp $
  4.     $Log: opendevice.c,v $
  5.     Revision 1.4  1996/08/13 13:56:05  digulla
  6.     Replaced __AROS_LA by __AROS_LHA
  7.     Replaced some __AROS_LH*I by __AROS_LH*
  8.     Sorted and added includes
  9.  
  10.     Revision 1.3  1996/08/01 17:41:15  digulla
  11.     Added standard header for all files
  12.  
  13.     Desc:
  14.     Lang: english
  15. */
  16. #include <exec/execbase.h>
  17. #include <exec/devices.h>
  18. #include <exec/io.h>
  19. #include <exec/errors.h>
  20. #include <aros/libcall.h>
  21.  
  22. /*****************************************************************************
  23.  
  24.     NAME */
  25.     #include <exec/libraries.h>
  26.     #include <clib/exec_protos.h>
  27.  
  28.     __AROS_LH4(BYTE, OpenDevice,
  29.  
  30. /*  SYNOPSIS */
  31.     __AROS_LHA(STRPTR,             devName,    A0),
  32.     __AROS_LHA(ULONG,              unitNumber, D0),
  33.     __AROS_LHA(struct IORequest *, iORequest,  A1),
  34.     __AROS_LHA(ULONG,              flags,      D1),
  35.  
  36. /*  LOCATION */
  37.     struct ExecBase *, SysBase, 74, Exec)
  38.  
  39. /*  FUNCTION
  40.     Tries to open a device and fill the iORequest structure.
  41.     And error is returned if this fails, 0 if all went well.
  42.  
  43.     INPUTS
  44.     devName    - Pointer to the devices's name.
  45.     unitNumber - The unit number. Most often 0.
  46.     iORequest  - Pointer do device specific information.
  47.              Will be filled out by the device.
  48.              Must lie in public (or at least shared) memory.
  49.     flags       - Some flags to give to the device.
  50.  
  51.     RESULT
  52.     Error code or 0 if all went well. The same value can be found
  53.     in the io_Error field.
  54.  
  55.     NOTES
  56.  
  57.     EXAMPLE
  58.  
  59.     BUGS
  60.  
  61.     SEE ALSO
  62.     CloseDevice()
  63.  
  64.     INTERNALS
  65.  
  66.     HISTORY
  67.  
  68. *****************************************************************************/
  69. {
  70.     __AROS_FUNC_INIT
  71.  
  72.     __AROS_BASE_EXT_DECL(struct ExecBase *,SysBase)
  73.     struct Device *device;
  74.     BYTE ret=IOERR_OPENFAIL;
  75.  
  76.     /* Arbitrate for the device list */
  77.     Forbid();
  78.  
  79.     /* Look for the device in our list */
  80.     device=(struct Device *)FindName(&SysBase->DeviceList,devName);
  81.  
  82.     /* Something found ? */
  83.     if(device!=NULL)
  84.     {
  85.     /* Init iorequest */
  86.     iORequest->io_Error=0;
  87.     iORequest->io_Device=device;
  88.     iORequest->io_Flags=flags;
  89.     iORequest->io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  90.  
  91.     /* Call Open vector. */
  92.     __AROS_LVO_CALL3(void,1,device,iORequest,A1,unitNumber,D0,flags,D1);
  93.  
  94.     /* Check for error */
  95.     ret=iORequest->io_Error;
  96.     if(ret)
  97.         /* Mark request as non-open */
  98.         iORequest->io_Device=NULL;
  99.     }
  100.     /*
  101.     else
  102.     {
  103.     Under normal circumstances you'd expect the device loading here -
  104.     but this is only exec which doesn't know anything about the
  105.     filesystem level. Therefore dos.library has to SetFunction() this vector
  106.     for the additional functionality.
  107.     }
  108.     */
  109.  
  110.     /* All done. */
  111.     Permit();
  112.     return ret;
  113.     __AROS_FUNC_EXIT
  114. } /* OpenDevice */
  115.  
  116.